package com.boomsecret.juc.atomic;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author wangjinliang on 2019/1/17.
 */
public class AtomicLongDemo {

    public static void main(String[] args) {
        // 和AtomicInteger差不多 所以随意看看
        AtomicLong atomicLong = new AtomicLong();

        System.out.println(atomicLong.getAndUpdate(operand -> operand + 10));
        System.out.println(atomicLong.get());

        System.out.println("-------------");
        System.out.println(atomicLong.updateAndGet(operand -> operand + 10));
        System.out.println(atomicLong.get());

        System.out.println("-------------");
        System.out.println(atomicLong.getAndAccumulate(80, (left, right) -> left + right));
        System.out.println(atomicLong.get());

        System.out.println("-------------");
        System.out.println(atomicLong.accumulateAndGet(1, (left, right) -> left + right));
        System.out.println(atomicLong.get());
    }
}
